# Maintainer: Haroogan <Haroogan@gmail.com>
# Contributer: Martell Malone <martellmalone@gmail.com>

_realname='conemu'
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r3199.5dc44c0
pkgrel=1
pkgdesc="Customizable Windows console emulator with tabs (mingw-w64)"
url="https://code.google.com/p/${_realname}-maximus5/"
license=('BSD New')
arch=('any')
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "git")
# CAUTION:
# Don't remove `!strip' option!  Otherwise, 64-bit version of ConEmu will signal
# errors at startup.
options=('!strip'
         'staticlibs')
source=("${_realname}"::"git+https://github.com/Haroogan/ConEmu.git#branch=msys2"
        'ConEmu.xml')
sha256sums=('SKIP'
            '84c201cf676aae844a5c00b20ce8912f004562422a3e340fe01c786ab666062c')

pkgver() {
  cd "${_realname}"
  printf 'r%s.%s' "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  cd "${_realname}/src"

  # CAUTION:
  # Don't remove `-static*' switches from `USERLIBSFIRST'!  Otherwise, when
  # running `cmd.exe' (Command Prompt) in ConEmu, it cannot find
  # `libstdc++-6.dll' if it is not in the current `PATH' environment variable.
  make                                                                         \
    -j1                                                                        \
    -f makefile_all_gcc                                                        \
             WIDE="1"                                                          \
          USERCPP="-pipe -O3 -fomit-frame-pointer -fpermissive -std=c++11"     \
    USERLIBSFIRST="-static -static-libgcc -static-libstdc++"
}

package() {
  local suffix=''

  if test "${CARCH}" == 'x86_64'; then
    suffix='64'
  fi

  mkdir -p "${pkgdir}${MINGW_PREFIX}/bin"

  cp -r "ConEmu.xml" "${pkgdir}${MINGW_PREFIX}/bin"

  cd "${_realname}/Release"

  cp -r "ConEmu.exe" "${pkgdir}${MINGW_PREFIX}/bin/"

  cd "ConEmu"

  cp -r "ConEmuC.exe"  "${pkgdir}${MINGW_PREFIX}/bin/ConEmuC${suffix}.exe"
  cp -r "ConEmuCD.dll" "${pkgdir}${MINGW_PREFIX}/bin/ConEmuCD${suffix}.dll"
  cp -r "ConEmuHk.dll" "${pkgdir}${MINGW_PREFIX}/bin/ConEmuHk${suffix}.dll"
}
